const app = getApp();
Page({
  data: {
    url: app.apiroot,
    loading: true,
    bank: {
      money: 0,
      lack_money: 0,
      income_monney: 0,
      shop_money: 0
    },
    list: [],
    today: 0,
    page: 0,
    active:0
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.isLogin(()=>{
      this.getBank();
    });
  },
  // 下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    }, 1500);
    this.setData({
      page: 0,
      loading: true,
      list: [],
      bank: {
        money: 0,
        lack_money: 0,
        income_monney: 0,
        shop_money: 0
      },
    });
    this.getBank();
  },
  //上拉加载更多
  onReachBottom: function () {
    this.setData({
      loading: true,
    }); 
    this.getList();
  },
  /**
   * 点击切换
   */
  onChange(event) {
    this.setData({
      loading: true,
      page: 0,
      list: [],
      today: event.detail.name
    });
    this.getList();
  },
  //点击链接
  ontabbar(event) {
    wx.navigateTo({
      url: event.detail,
    })
  },
   /**
    * 帐号余额
    */
  getBank: function () {
    var param = {
      'signkey': app.util().getRandom(12)
    }
    app.api().Get("api/v4/allwin/bank/index", param,(result) => {
      if (result.code == 200){
        this.setData({
          bank: result.data
        });
        this.getList();
      }
    })
  },
  /**
   * 账单
   */
  getList: function () {
    if (this.data.loading) {
      var param = {
        page: this.data.page + 1,
        today: this.data.today
      }
      app.api().Get("api/v4/allwin/bank/bill", param,(result) => {
        if (result.code == 200) {
          var list = this.data.list;
          for (let i in result.data) {
            list.push(result.data[i]);
          }
          this.setData({
            list: list,
            page: param.page,
          });
        }
      })
      this.setData({
        loading: false,
      });
    }
  }
})